# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=zoxide
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.7
pkgrel=1
pkgdesc="A smarter cd command (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/ajeetdsouza/zoxide'
msys2_references=(
  'purl: pkg:cargo/zoxide'
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
checkdepends=('fish' 'zsh')
options=('!strip')
source=("https://github.com/ajeetdsouza/zoxide/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('d93ab17a01de68529ef37b599524f882dc654835cc121a9097dd3f2952fd207e')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  cargo build --release --frozen
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 contrib/completions/zoxide.bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/zoxide"
  install -Dm644 contrib/completions/_zoxide "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_zoxide"
  install -Dm644 contrib/completions/zoxide.fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/zoxide.fish"
  install -Dm644 man/man1/* -t "${pkgdir}${MINGW_PREFIX}/share/man/man1/"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
